package com.jack.thinking.thread.core._1;

public class StopThreadTest2 {
	public static void main(String[] args) throws Exception {
		try {
			Thread tar = new Thread(new StopRunnable2());
			tar.start();
			Thread.sleep(100L);
			tar.interrupt();
		} catch (Exception e) {
			System.out.println(e);
			e.printStackTrace();
		}
	}
}


class StopRunnable2 extends Thread{

	@Override
	public void run() {
		super.run();
		try {
			for(int i = 0 ; i < 500000 ; i ++) {
				if(Thread.interrupted()) {
					System.out.println("已退出");
					throw new InterruptedException("thread is interrupted.....");
				}
				System.out.println(i);
			}
		} catch (InterruptedException e) { 
			System.out.println("-" + e.getMessage());
			e.printStackTrace();
		}
	}
	
}